# 游戏信息

# 文字信息
import pygame
from .. import constants as C
from . import coin
from .. import setup, tools
pygame.font.init()
# clock = pygame.time.Clock()
class Info:
    def __init__(self, state, game_info):
        self.state = state
        self.game_info = game_info
        self.create_state_labels()  # 创建特有的文字
        self.create_info_labels()  # 创建通用文字
        self.flash_coin = coin.FlashingCoin()
        # 倒计时
        # self.text_objects()
        # self.game_clock()

    def create_state_labels(self):
        self.state_labels = []
        if self.state == 'main_menu':
            self.state_labels.append((self.create_label('1  PLAYER  GAME'), (272, 360)))
            self.state_labels.append((self.create_label('2  PLAYER  GAME'), (272, 405)))
            self.state_labels.append((self.create_label('TOP - '), (290, 465)))
            self.state_labels.append((self.create_label('000000'), (400, 465)))

        elif self.state == 'load_screen':
            self.state_labels.append((self.create_label('WORLD'), (280, 200)))
            self.state_labels.append((self.create_label('1 - 1'), (430, 200)))
            self.state_labels.append((self.create_label('X    3'), (380, 280)))
            self.player_image = tools.get_image(setup.GRAPHICS['mario_bros'], 178, 32, 12, 16, (0, 0, 0), C.BG_MULTI)
        elif self.state == 'game_over':
            self.state_labels.append((self.create_label('GAME OVER'), (280, 300)))

    def create_info_labels(self):
        self.info_labels = []
        self.info_labels.append((self.create_label('MARIO'), (75, 30)))
        self.info_labels.append((self.create_label('WORLD'), (450, 30)))
        self.info_labels.append((self.create_label('TIME'), (625, 30)))
        # self.info_labels.append((self.create_label(str(self.game_clock())), (637, 55)))
        self.info_labels.append((self.create_label('{}'.format(self.game_info['time'])), (637, 55)))
        self.info_labels.append((self.create_label('{}'.format(self.game_info['score'])), (120, 55)))
        # self.info_labels.append((self.create_label('000000'), (75, 55)))
        self.info_labels.append((self.create_label('x  {}'.format(self.game_info['coin'])), (300, 55)))
        self.info_labels.append((self.create_label('1 - 1'), (480, 55)))
        # pygame.display.flip()



        # self.info_labels.append((self.game_clock(), (625, 55)))

    def create_label(self, label, size=40, width_scale=1.25, height_scale=1):
        font = pygame.font.SysFont(C.FONT, size)
        label_image = font.render(label, 1, (255, 255, 255))   # 将文字渲染成图片
        rect = label_image.get_rect()
        label_image = pygame.transform.scale(label_image, (int(rect.width * width_scale),
                                                           int(rect.height * height_scale)))
        return label_image


    def update(self):
        self.flash_coin.update()
        self.create_info_labels()


    def draw(self, surface):
        for label in self.state_labels:
            surface.blit(label[0], label[1])  # 0代表图片，1代表位置
        for label in self.info_labels:
            surface.blit(label[0], label[1])

        surface.blit(self.flash_coin.image, self.flash_coin.rect)

        if self.state == 'load_screen':
            surface.blit(self.player_image, (300, 270))

    # def text_objects(text, font):
    #     textSurface = font.render(text, True, (0, 0, 0))
    #     # 在一个新 Surface 对象上绘制文本
    #     return textSurface, textSurface.get_rect()

    # def game_clock(self):
    #     t = pygame.time.get_ticks()  # 该时间指的从pygame初始化后开始计算，到调用该函数为止
    #     return int(300-t/1000)
    #     clock_ = 300
    #     print(clock_)
        # while True:
        #     pygame.time.get_ticks()
        #     if (pygame.time.get_ticks() % 1000 == 0):
        #         clock_ = clock_ - 1
        #         clock_g = str(clock_)
        #         largeText = pygame.font.SysFont('comicsansms', 25)
        #         TextSurf, TextRect = self.text_objects(clock_g, largeText)
        #         TextRect.center = (750, (C.SCREEN_H / 10))
        #         setup.SCREEN.blit(TextSurf, TextRect)
        #         pygame.display.update()
        #         clock.tick(15)
        #         print(clock_)


